package com.zsc.graduate.qovipan.controller;

import com.zsc.graduate.qovipan.util.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.logging.Logger;

/**
 * @author 枫树下奶罐
 * @version 1.0.0
 * @date 2022/2/11 16:15
 */
@Controller
public class RegisterController {
    private Logger log;

    @GetMapping("/userreg")
    public String userRegBack(Model model){
        log = Logger.getLogger("getMethod.reject");
        log.info("请不要使用get方法提交");
        model.addAttribute("tips_warn", "color: red;");
        model.addAttribute("tips", "请不要使用get方法提交");
        return "register";
    }
    @PostMapping("/userreg")
    public String userReg(@RequestParam("username") String username,
                          @RequestParam("password") String password,
                          @RequestParam("email") String email, Model model) {
        log = Logger.getLogger("postMethod.login.submit");
        log.info("提交成功");
        if(username.equals("")  || password.equals("")){
            log.info("账号或密码不能为空！");
            model.addAttribute("tips_warn", "color: red;");
            model.addAttribute("tips", "账号或密码不能为空！");
            return "register";
        }
//        User u = new User();
//        u.setUsername(username);
//        u.setPassword(password);
        log.info("用户名: "+ username +" 密码: "+ password +"邮箱: "+ email);
        model.addAttribute("username", username);
        model.addAttribute("password", password);
        model.addAttribute("email", email);
        return "log";
    }
}
